package com.CityHunter.Common;



import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;

import android.util.Log;

public class Http {
	
	JSONArray json = null;
	
	public JSONArray sendRequest(String page,List<NameValuePair> params){
		HttpPost httpRequest = new HttpPost(page);
		DefaultHttpClient httpclient = new DefaultHttpClient();
		try{
			// send request
			httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
			// get response
			HttpResponse httpResponse = httpclient.execute(httpRequest);
			// if connection status is OK
			if (httpResponse.getStatusLine().getStatusCode() == 200){
				String strResult = EntityUtils.toString(httpResponse.getEntity());
				json = new JSONArray(strResult);
				Log.d("Http_Debug","Connect successful");
			} 
		}catch (Exception e){
			Log.e("Http_Error",e.getMessage().toString());
		}
		return json;
	}
}
